package com.z.dao.impl;

import com.z.dao.TypeDao;
import com.z.pojo.Type;
import com.z.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 张福兴
 * date 2021/9/2
 */

public class TypeDaoImpl implements TypeDao {
    private Connection conn = null;
    private PreparedStatement ps = null;
    @Override
    public List<Type> selectAllType() throws SQLException {
        this.conn = DBUtil.getConnection();

        String sql="select * from type ;";
        this.ps = this.conn.prepareStatement(sql);
        ResultSet resultSet = this.ps.executeQuery();
        List<Type> list = new ArrayList<>();
        while (resultSet.next()) {
            list.add(new Type(resultSet.getInt("tid"),resultSet.getString("tname")));
        }
        DBUtil.close(this.ps,this.conn);
        return list;
    }
}
